﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SevenWizards1.CoreComponents;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace SevenWizards1
{
    class NewGameScreen : GameScreen
    {
        ButtonMenu buttonMenu;

        int name = 0;
        bool gender = false;
        int difficultyLevel = 1;
        int className = 0;
        Texture2D buttonImage;
        int screenWidth;
        int screenHeight;

        string[] classNames = {
            "Fighter",
            "Wizard",
            "Thief",
            "Priest" };

        string[] menuItems = {
            "FORSEE HERO'S NAME",
            "FORSEE HERO'S GENDER",
            "FORSEE HERO'S CLASS",
            "FORSEE DIFFICULTY LEVEL",
            "BACK TO MENU",
            "BEGIN THE ADVENTURE" };

        string[] difficultyLevels = {
            "Easy",
            "Normal",
            "Hard",
            "Ultimate" };

        public static readonly string[] MaleNames = {
            "Aris",
            "Barton",
            "Evander",
            "Kalven",
            "Llelwyn" };

        public static readonly string[] FemaleNames = {
            "Anwyn",
            "Bronwyn",
            "Cantrian",
            "Julia",
            "Zoey" };

        SpriteFont spriteFont;
        SpriteBatch spriteBatch;
        ContentManager Content;

        public NewGameScreen(Game game, SpriteFont spriteFont)
        : base(game)
        {
            spriteBatch =
                (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            Content =
                (ContentManager)Game.Services.GetService(typeof(ContentManager));
            this.spriteFont = spriteFont;
            Components.Add(new BackgroundComponent(game,
                Content.Load<Texture2D>("Wizard")));
            buttonImage = Content.Load<Texture2D>(@"GUI\buttonbackground");
            buttonMenu = new ButtonMenu(game, spriteFont, buttonImage);
            buttonMenu.SetMenuItems(menuItems);
            Components.Add(buttonMenu);

            screenWidth = Game.Window.ClientBounds.Width;
            screenHeight = Game.Window.ClientBounds.Height;
        }

        public int SelectedIndex
        {
            get { return buttonMenu.SelectedIndex; }
        }

        public bool Gender
        {
            get { return gender; }
        }

        public void ChangeName(int name)
        {
            this.name = name;
        }

        public void ChangeGender(bool gender)
        {
            this.gender = gender;
        }

        public void ChangeDifficulty(int difficultyLevel)
        {
            this.difficultyLevel = difficultyLevel;
        }

        public void ChangeClass(int className)
        {
            this.className = className;
        }

        public override void Show()
        {
            buttonMenu.Position = new Vector2((Game.Window.ClientBounds.Width -
                                          buttonMenu.Width) / 2, 200);
            base.Show();
        }

        public override void Draw(GameTime gameTime)
        {
            Vector2 position = new Vector2();
            string characterString;

            if (gender)
            {
                characterString = FemaleNames[name] + " the ";
            }
            else
            {
                characterString = MaleNames[name] + " the ";
            }

            base.Draw(gameTime);
            
            characterString += classNames[className];
            Vector2 stringSize = spriteFont.MeasureString(characterString);
            position.X = (screenWidth - stringSize.X) / 2;
            position.Y = 080;
            
            spriteBatch.DrawString(spriteFont,
                characterString,
                position + Vector2.One * 3,
                Color.Black);
            
            spriteBatch.DrawString(spriteFont,
                characterString,
                position,
                Color.White);
            
            characterString = "Playing in " + difficultyLevels[difficultyLevel];
            characterString += " mode";
            stringSize = spriteFont.MeasureString(characterString);
            position.X = (screenWidth - stringSize.X) / 2;
            position.Y += spriteFont.LineSpacing;
            
            spriteBatch.DrawString(spriteFont,
                characterString,
                position + Vector2.One * 3,
                Color.Black);
            
            spriteBatch.DrawString(spriteFont,
                characterString,
                position,
                Color.White);
        }
    }
}
